import { myUserinfo } from '@/api/login.js'
export default {
  namespaced: true,
  state: {
    token: '',
    userInfo: ''
  },
  // this.$store.state.login.token
  mutations: {
    setToken (state, value) {
      state.token = value
    },
    // 调用mutations:this.$store.commit('login/setToken',实参)
    // 修改userInfo
    setUserInfo (state, value) {
      state.userInfo = value
    },
    // 清除用户信息与token
    logout (state) {
      state.token = ''
      state.userInfo = ''
    }
  },
  actions: {
    async getUserInfo (store) {
      // store:{state,commit}
      // myUserinfo().then(res => {
      //   store.commit('setUserInfo', res.data)
      //   console.log('用户信息', res)
      //   console.log(3)
      // })
      const res = await myUserinfo()
      store.commit('setUserInfo', res.data)
      console.log('用户信息', res)
      console.log(3)
    }
    // this.$store.dispatch('模块名/actions方法名',实参)
  },
  getters: {}
}
